﻿/// <reference path="~/Scripts/FlowBasis/FlowBasis-all-vsdoc.js" />

FlowBasis.defineNamespace("UI");

FlowBasis.UI.alert = function (messageHtml, title, callback) {
    /// <summary>
    /// Show alert dialog and call callback function after it is dismissed.
    /// </summary>

    var alertBody = jQuery("<div>")
        .css({ display: "none" })
        .html(messageHtml)
        .appendTo(document.body);

    var dialogOptions = {
        modal: true,

        buttons: [
            {                
                text: "OK",
                click: function() {
                    jQuery(alertBody).dialog("destroy");
                    alertBody.remove();

                    if (callback) {
                        callback();
                    }
                }
            }
        ]
    };

    if (title) {
        dialogOptions.title = title;
    }

    alertBody.dialog(dialogOptions);           
};


FlowBasis.UI.confirm = function (messageHtml, title, callback) {
    /// <summary>
    /// Show alert dialog and call callback function after it is dismissed.
    /// Callback should be of form function (confirmed).
    /// </summary>

    var confirmBody = jQuery("<div>")
        .css({ display: "none" })
        .html(messageHtml)
        .appendTo(document.body);

    var dialogOptions = {
        modal: true,

        buttons: [
            {                
                text: "OK",
                click: function() {
                    jQuery(confirmBody).dialog("destroy");
                    confirmBody.remove();

                    if (callback) {
                        callback(true);
                    }
                }
            },
            {                
                text: "Cancel",
                click: function() {
                    jQuery(confirmBody).dialog("destroy");
                    confirmBody.remove();

                    if (callback) {
                        callback(false);
                    }
                }
            },
        ]
    };

    if (title) {
        dialogOptions.title = title;
    }

    confirmBody.dialog(dialogOptions);           
};